package cn.yunhe.servlet;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import cn.yunhe.biz.AdminBiz;
import cn.yunhe.entity.Admin;

public class AdminLoginServlet extends HttpServlet {
	
	
	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		
		String name=request.getParameter("loginId");
		String password=request.getParameter("password");
		HttpSession session=request.getSession();
		
		
		AdminBiz adminBiz=new AdminBiz();
		
		Admin admin=adminBiz.adminLogin(name, password);
		
		if(admin!=null){
			session.setAttribute("admin", admin);
			request.getRequestDispatcher("mainform.jsp").forward(request, response);		
		}else{
			response.sendRedirect("adminLogin.jsp");
		}
	}
	
 	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {
 		doGet(request, response);
	}
}
